/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Session;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import Entity.Redacteur;
import javax.persistence.Query;
/**
 *
 * @author Gautch
 */
@Stateless
public class RedacteurSession implements RedacteurSessionLocal {
    @javax.persistence.PersistenceContext(unitName = "Assurance-ejbPU")
    private EntityManager em;
    
     public boolean connexion(String login, String pwd){
        System.out.println("connexion redac");
        if(login != null && pwd != null) {
            System.out.println("login et pwd != null");
            System.out.println("login= "+login+" et pwd = "+pwd);

            Query test = em.createNamedQuery("Redacteur.findByIdredac");
            
           // System.out.println("aaa" + test.toString());

            test.setParameter("idredac",  login) ;
            System.out.println("bbb");

            Redacteur r = (Redacteur) test.getSingleResult();
            System.out.println("ccc");

            System.out.println("login vrai= "+r.getIdredac()+" et pwd = "+r.getMdpredac());

            if(r.getIdredac().equals(login) && r.getMdpredac().equals(pwd)) {
                        System.out.println("connexion redac3");

                return true;
            }
        }
        return false;
    }
    
}
